#!/bin/bash

G_CHIP_NAME="$1"
G_OEM_NAME="$2"

../com_clean.sh $G_OEM_NAME
echo "clean.sh $G_OEM_NAME"

cp tools/$G_OEM_NAME/app_init.sh    filesys/system/init/ -rf
cp tools/$G_OEM_NAME/*.conf         filesys/etc/jffs2/ -rf
cp tools/$G_OEM_NAME/bak/*          filesys/usr/ipcam/bak/ -rf
cp tools/$G_OEM_NAME/etc/*          filesys/etc/  -rf
cp tools/$G_OEM_NAME/sounds/*       filesys/usr/share/sounds/ -rf
cp tools/$G_OEM_NAME/root/*         filesys/root/  -rf
chmod 777 filesys/root/ -R
cp tools/$G_OEM_NAME/bak/*          filesys/usr/ipcam/bak -rf
cp tools/$G_OEM_NAME/bin/*          filesys/usr/sbin/  -rf
cp tools/$G_OEM_NAME/lib/*          filesys/usr/lib/  -rf
cp tools/$G_OEM_NAME/sys_lib/*      filesys/lib/  -rf
cp tools/$G_OEM_NAME/modules/*      filesys/lib/modules/ -rf
cp tools/$G_OEM_NAME/usr/*          filesys/usr/ -rf
cp tools/$G_OEM_NAME/config/*       filesys/system/config/ -rf

if [ -d tools/$G_OEM_NAME/appfs ];then
    rm ../appfs/* -rf
    mkdir -p tools/$G_OEM_NAME/appfs/bak
    mkdir -p tools/$G_OEM_NAME/appfs/bin
    mkdir -p tools/$G_OEM_NAME/appfs/lib
    mkdir -p tools/$G_OEM_NAME/appfs/wav
    mkdir -p tools/$G_OEM_NAME/appfs/configs
    touch tools/$G_OEM_NAME/appfs/appfs_ok
    chmod 777 tools/$G_OEM_NAME/appfs -R
    rm tools/$G_OEM_NAME/appfs/bak/* -rf
    rm tools/$G_OEM_NAME/appfs/bin/* -rf
    rm tools/$G_OEM_NAME/appfs/lib/* -rf
    rm tools/$G_OEM_NAME/appfs/wav/* -rf
    rm tools/$G_OEM_NAME/appfs/configs/* -rf
    cp tools/$G_OEM_NAME/appfs_wav/* tools/$G_OEM_NAME/appfs/wav/ -rf
    cp tools/$G_OEM_NAME/appfs_configs/* tools/$G_OEM_NAME/appfs/configs/ -rf
    cp filesys/usr/ipcam/bak/soc_version.txt tools/$G_OEM_NAME/appfs/bak/
    cp filesys/usr/sbin/iot_ipc tools/$G_OEM_NAME/appfs/bin/
    if [[ "$G_CHIP_NAME" != TX* ]];then
        cp -d filesys/usr/lib/* tools/$G_OEM_NAME/appfs/lib/
    fi
fi

